package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.query.StrategyTravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyTravel")
public class StrategyTravelController {
    @Autowired
    private ITravelService travelService;
    //显示页面
    @RequestMapping("list")
    public String list(@ModelAttribute("qo") StrategyTravelQueryObject qo, Model model){
        //如果大攻略不为空就查 出其所 已经关联的游记
        if(qo.getStrategyId() !=null){
            qo.setOrderBy("t.createTime desc");
            model.addAttribute("pageInfo",travelService.listTravelCommentByStategyId(qo));
        }
        return "/strategy/travel";
    }
    @RequestMapping("deleteRelation")
    @ResponseBody
    public Object list(Long strategyId,Long travelId){
        //删除中间表关系
        travelService.deleteRelation(strategyId,travelId);
        return new JsonResult();
    }
    @RequestMapping("insertRelation")
    @ResponseBody
    public Object insertRelation(Long strategyId,Long travelId){
        //删除中间表关系
        travelService.insertRelation(strategyId,travelId);
        return new JsonResult();
    }
}
